package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/jsonparm")
public class ParamJsonController {
    //
   /* @ResponseBody
    @RequestMapping("/json1")
    public String json1(@RequestBody List<String> list){
        System.out.println(list);
        return "{'info':'hello'}";
    }*/


    /*@ResponseBody
    @RequestMapping("/json2")
    public String json2(@RequestBody User user){
        System.out.println(user);

        return "{'info':'hello'}";
    }*/

    /*@ResponseBody
    @RequestMapping("/json3")
    public String json3(@RequestBody List<User>list){
        System.out.println(list);
        return "{'info':'hello'}";
    }*/

    //响应页面
    /*@RequestMapping("/resp")
    public String response(){
        System.out.println("跳转页面");
        return "index.html";
    }*/


    /*//返回值为集合对象，设置返回值为集合类型，即可实现返回对应集合的json数组数据，需要依赖
    //@RequestMapping
    // @ResponseBody
   @RequestMapping("/tojsonpojo")
   @ResponseBody
    public User tojsonpojo(){
        System.out.println("返回json对象数据");
        User user = new User();
        user.setName("zx");
        user.setAge(8);
        return user;
    }*/

    /*//响应POJO集合对象
//返回值为集合对象，设置返回值为集合类型，即可实现返回对应集合的json数组数据，
//需要依赖@ResponseBody注解和@EnableWebMvc注解
    @RequestMapping("/toJsonList")
    @ResponseBody
    public List<User> toJsonList(){
        System.out.println("返回json集合数据");
        User user1 = new User();
        user1.setName("传智播客");
        user1.setAge(15);

        User user2 = new User();
        user2.setName("黑马程序员");
        user2.setAge(12);

        List<User> userList = new ArrayList<User>();
        userList.add(user1);
        userList.add(user2);

        return userList;
    }*/

}
